package define

import "gitee.com/jjawesomejj/awesomehttp/system/helper"

type BaseError struct {
	s string
}

type BaseErrorMsg interface {
	BaseError() string // 实现这个接口 panic 的内容不会被拦截 而是直接输出
}

func New(text string) *BaseError {
	return &BaseError{text}
}

// errorString is a trivial implementation of error.
type errorString struct {
	s string
}

func (e *BaseError) Error() string {
	return e.s
}

type RequestError struct {
	errorMsg  string
	errorCode int
}

func (e *RequestError) BaseError() string {
	return e.Error()
}

func (e *RequestError) Error() string {
	return helper.JsonEncode(BaseResponse{
		Data:  "",
		Errno: e.errorCode,
		Msg:   e.errorMsg,
		Ptime: 0,
	})
}
func NewRequestError(errorMsg string, errorCode int) error {
	e := &RequestError{}
	e.errorCode = errorCode
	e.errorMsg = errorMsg
	return e
}
